package schach.server.view;

import java.awt.event.*;
import java.awt.Frame;
import java.awt.Graphics;
import java.io.File;
import java.io.IOException;

import javax.imageio.*;
import java.awt.image.BufferedImage;
import java.awt.*;

public class Bild {
	String name;
	BufferedImage image;
	private int x;
	private int y;
	private final int xVerschiebung = 53;
	private final int yVerschiebung = 536;
	// Geben an um wie viel das nächste Feld verschoben ist z.B. 50 Pixel
	private final int xMultiplikator = 50;
	private final int yMultiplikator = 50;
	private final String[] bilderWeiss = {"bauer_w.png", "dame_w.png", "koenig_w.png", "laeufer_w.png", "springer_w.png", "turm_w.png"};
	private final String[] bilderSchwarz = {"bauer_b.png", "dame_b.png", "koenig_b.png", "laeufer_b.png", "springer_b.png", "turm_b.png"};
	private final String filepath = "src/schach/server/view/";

	public Bild(String figur, boolean isBlack, int x, int y, Graphics g) {
		this.x = x;
		this.y = y;
		int laengeName = figur.length();
		String FigurName = figur.substring(laengeName-3, laengeName);
		BufferedImage bild = null;
		
		if (isBlack){
			for (int i = 0; i < bilderSchwarz.length; i++) {
				if (bilderSchwarz[i].contains(FigurName)){
					try {
						bild = ImageIO.read(new File(filepath + bilderSchwarz[i]));
					} catch (Exception e) {
						System.out.println(e.getMessage());
					}
				}
			}
		}
		else{
			for (int i = 0; i < bilderWeiss.length; i++) {
				if (bilderWeiss[i].contains(FigurName)){
					try {
						bild = ImageIO.read(new File(filepath + bilderWeiss[i]));
					} catch (Exception e) {
						System.out.println(e.getMessage());
					}
				}
			}
		}
		
		
		g.drawImage(bild, (xVerschiebung + x * xMultiplikator),
				(yVerschiebung - y * yMultiplikator), null);
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

}
